package com.atguigu.srb.base.controller;

import com.atguigu.srb.base.utils.MinioClientUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.InputStream;

/**
 * @Description TODO
 * @Classname MinioTestController
 * @Date 2022/11/21 16:37
 * @Created by 16342
 * @Author wangchengshan
 */
@RestController
@RequestMapping("minio")
@Slf4j
public class MinioTestController {

    @Resource
    private MinioClientUtil minioClientUtil;

    @Value("${minio.url:http:101.34.91.86:60053}")
    private String url;

    @Value("${minio.bucket:srb}")
    private String bucket;


    @PutMapping("upload/file")
    public Boolean uploadFIle(MultipartFile file, InputStream stream){
        try {
            minioClientUtil.uploadFile(bucket,file.getOriginalFilename(),stream,file.getSize());
        }catch (Exception e){
            System.out.println(e);
            log.error("文件上传失败" + e);
        }
        return true;
    }
}
